<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 转化数字的最小运算数 -->
    <script>
      var minimumOperations = function (nums, start, goal) {
        let q = []
        let vis = new Array(1001).fill(0)
        q.push([start, 0])
        while (q.length) {
          let [t, dis] = q.shift()
          for (let i of nums) {
            for (let tt of [t + i, t - i, t ^ i]) {
              if (tt === goal) {
                return dis + 1
              }
              if (tt >= 0 && tt <= 1000 && vis[tt] === 0) {
                vis[tt] = dis + 1
                q.push([tt, dis + 1])
              }
            }
          }
        }
        return -1
      }
      console.log(minimumOperations([2, 4, 12], 2, 12))
    </script>
  </body>
</html>
